<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.*" %>
<%@ page import="java.io.IOException" %>
<%@ page import="com.thinkgem.jeesite.modules.devmng.entity.DeviceManual" %>
<%@ page import="com.thinkgem.jeesite.modules.devmng.entity.DeviceMain" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>设备管理</title>
    <meta name="decorator" content="default"/>
    <script type="text/javascript">
        $(document).ready(function () {
            //$("#name").focus();
            $("#inputForm").validate({
                submitHandler: function (form) {
                    loading('正在提交，请稍等...');
                    form.submit();

                },
                errorContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
        });
    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li><a href="${ctx}/devmng/deviceMain/">设备列表</a></li>
    <li class="active"><a href="${ctx}/devmng/deviceMain/from?id=${deviceMain.id}">设备<shiro:hasPermission
            name="devmng:deviceMain:edit">${not empty deviceMain.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission
            name="devmng:deviceMain:edit">查看</shiro:lacksPermission></a></li>
</ul>
<br/>
<form:form id="inputForm" modelAttribute="deviceMain" action="${ctx}/devmng/deviceMain/save" method="post"
           class="form-horizontal" enctype="multipart/form-data">
    <form:hidden path="id"/>
    <sys:message content="${message}"/>
    <div class="control-group">
        <label class="control-label">设备名称：</label>
        <div class="controls">
            <form:input path="deviceName" htmlEscape="false" maxlength="50" class="input-xlarge required"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">设备编码：</label>
        <div class="controls">
            <form:input path="deviceCode" htmlEscape="false" maxlength="50" class="input-xlarge required"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">设备类型：</label>
        <div class="controls">
            <sys:treeselect id="deviceType" name="deviceType.id" value="${deviceMain.deviceType.id}"
                            labelName="deviceType.name" labelValue="${deviceMain.deviceType.name}"
                            title="设备类型" url="/devmng/deviceType/treeData" cssClass="required" allowClear="true"
                            notAllowSelectParent="true"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">设备图片：</label>
        <div class="controls">
            <input type="file" name="deviceImgFile"/>
            <c:if test="${not empty deviceMain.deviceImgUrl}">
                <img src="${deviceMain.deviceImgUrl}"/>
            </c:if>
        </div>
    </div>

    <div class="control-group">
        <label class="control-label">设备手册：</label>
        <div class="controls">
            <input type="file" name="deviceManualFile" multiple/>
            <c:if test="${not empty deviceManual}">
                <c:set var="ctx" value="${ctx}" scope="request"/>
                <%!
                    private String ctx = "";
                    private List<DeviceManual> url = new ArrayList<DeviceManual>();
                %>
                <%
                    url = (List<DeviceManual>) request.getAttribute("deviceManual");
                     ctx = (String) request.getAttribute("ctx");
                        out.print("<br>");
                        for (int i = 1; i <= url.size();i++) {
                %>
                <a target="_blank "href="<%=url.get(i-1).getDeviceManualUrl()%>"><%=url.get(i-1).getDeviceManualName()%></a>
                &nbsp;&nbsp;
                <a href="${ctx}/devmng/deviceMain/manualDelete?id=<%=url.get(i-1).getId()%>" onclick="return confirmx('确认要删除该图片吗？', this.href)">删除</a>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <%
                        if (i%2 == 0) {
                                out.print("<br>");
                            }
                        }
                %>
            </c:if>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">包机人：</label>
        <div class="controls">
            <sys:treeselect id="deviceUser" name="deviceUser.id" value="${deviceMain.deviceUser.id}"
                            labelName="deviceUser.name" labelValue="${deviceMain.deviceUser.name}"
                            title="用户" url="/sys/office/treeData?type=3" cssClass="required"
                            allowClear="true" notAllowSelectParent="true"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">部门：</label>
        <div class="controls">
            <sys:treeselect id="sysOffice" name="sysOffice.id" value="${deviceMain.sysOffice.id}"
                            labelName="sysOffice.name" labelValue="${deviceMain.sysOffice.name}"
                            title="部门" url="/sys/office/treeData?type=2" cssClass="required" allowClear="true"
                            notAllowSelectParent="true"/>
            <span class="help-inline"><font color="red">*</font> </span>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">备注：</label>
        <div class="controls">
            <form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
        </div>

    </div>
    <input type="hidden" name="copyFlag" value="${copyFlag}" />
    <input type="hidden" name="copyId" value="${copyId}" />
    <div class="form-actions">

        <shiro:hasPermission name="devmng:deviceMain:edit"><input id="btnSubmit" class="btn btn-primary" type="submit"
                                                                  value="保 存"/>&nbsp;</shiro:hasPermission>
        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
    </div>
</form:form>
</body>
</html>